#include "Editor.h"


Screen& BasicEditor::screen = ScreenSingleton::instance();

int  BasicEditor::operator < (const BasicEditor& o) {
    if (point.y < o.point.y) {
        return -1;
    } else if (point.y > o.point.y) {
        return 1;
    } else {
        if (point.x < o.point.x) {
            return -1;
        } else if (point.x  > o.point.x) {
            return 1;
        } else {
            throw new std::invalid_argument("there are same position of Editor");
        }
    }
}


BasicEditor::BasicEditor(int lineNum, int startPos, int endPos, EditorType editorType) :point(startPos, lineNum), blankText(endPos - startPos + 1, ' ') {
    if (lineNum < 0 || lineNum >= Screen::SCREEN_HEIGHT) {
        throw  std::invalid_argument("editor line num invalid");
    }
    if (startPos < 0 || startPos >= Screen::SCREEN_WIDTH) {
        throw std::invalid_argument("editor startPos invalid");
    }
    if (endPos < 0 || endPos >= Screen::SCREEN_WIDTH) {
        throw std::invalid_argument("editor startPos invalid");
    }
    if (startPos > endPos) {
        throw std::invalid_argument("editor startPos invalid");
    }

    this->endPos = endPos;
    this->editorType = editorType;

    format[1] = '0' + blankText.length();

    maxCharactor = blankText.length();
    textBuffer.reserve(maxCharactor + 10);

    textBuffer.resize(maxCharactor);
}






